package com.andamios.sesamo.interceptor;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;


public class SesamoInterceptor extends HandlerInterceptorAdapter{
	
  private static Log log = LogFactory.getLog(SesamoInterceptor.class);  
  
      
      //@Value("${environment.production}")
     public Boolean isProduction=true;
   
    
        
 @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        try {
            HttpSession session = request.getSession(true);
            
           // bEmpGrlData bEmp = new bEmpGrlData();
            
           /* if (!isProduction) { 

                System.out.println("interceptor########");

            } else {
            	
            */	
            
            
        
            
            
            if(session.equals(null)){
            	response.sendRedirect("login.jsp");            	
            }else{
            	
            	/*System.out.println("xxxxx########"+request.getParameter("username"));
              	 bEmp.setId("1237");
                   bEmp.setNom("SOLANO/TORRES/HECTOR");
                   bEmp.setDep("804713");
                   bEmp.setLoc("3000");
                   bEmp.setNivel("9999");
                   bEmp.setCatego("GAM");
                   bEmp.setPlaza("20009871");
                   bEmp.setEmail("jesusdario.garcia@pepsico.com");
                   bEmp.setNomFormat("daniel cuevas");
                   bEmp.setGpid("1236");

                   session.setAttribute("userInSession", bEmp);*/
                   
                   return true;
            }
            
            
            	
                
           // }

        } catch (Exception ex) {
            log.error(ex);
            return false;
        }
        return super.preHandle(request, response, handler);
    }
 
    @Override
    public void postHandle(HttpServletRequest solicitud, HttpServletResponse respuesta,
            Object controlador, ModelAndView vista) throws IOException {
        try {
        } catch (Exception ex) {
           log.error(ex);
        }
    }

}
